import Ship
import Ships.BattleShipFSM.SM_Battleship
import ShipSprite
import os, sys, pygame, pygame.font
from random import *
from pygame.color import THECOLORS
from pygame.locals import *
import coords
import imageLoader

   
# **
# *  'HeadJoint', child of 'BaseJoint', contains a Finite State Machine (FSM) and also responsibilities 
# *  for updating and drawing itself. It also Handles Messages and directs Telegrams and corresponding 
# *  MessageDispatcher Instances to the FSM. 'HipJoint' is an active agent whose States are encapsulated 
# *  and interchanged within its FSM, through communications with the MessageDispatcher.
# *
# * PUBLIC FEATURES:
# *    // Constructors
# *    def __init__(self, ID, name, height, velocity, mass, speedMAX, forceMAX, turnRateMAX)
# *
# *    // Methods
# *    def getFSM(self)
# *    def handleMessage(self, msg, telegram)
# *    def render(self)
# *    def update(self, msg, time)
# *
# *    COLLABORATORS:
# *    BaseJoint
# *    Joints.HeadFSM.StateMachineHDJ
# *    visual
# *
# * MODIFIED:
# * @version 1.0, 2007-04-23 
# * @author Julian Andreou 5422329
# */

class Battleship(Ship.Ship):
    def __init__(self, position, map):
        Ship.Ship.__init__(self, position, map)
        #Ships.Ships.__init__(self, aRadius, pRadius, spawnPos, mass, velocity, heading, MAX_speed, MAX_force, MAX_turnRate) 
        
        self.FSM = Ships.BattleShipFSM.SM_Battleship.SM_Battleship(self)
        
    def getFSM(self):
        return self.FSM
    
    def handleInfluence(self, writer, influence):
        #self.FSM.handleInfluence(writer, influence)
        pass
    
    def update(self):
        self.FSM.update()


class BattleShipSprite(ShipSprite.ShipSprite):

   # We'll just accept the x-position here
   def __init__(self, position, map, screen):
       ShipSprite.ShipSprite.__init__(self, position, screen)
       self.ship = Ships.Battleship.Battleship(position, map)
       pygame.sprite.Sprite.__init__(self)
       self.image, self.rect = imageLoader.load_image('BattleShip.gif', -1)
       self.rect.topleft = position[0], position[1]


   def gridToScreen(self, gridCoords):
       #gridCoords.x = 44+(gridCoords.x * 16)-14
       #gridCoords.y = 44+(gridCoords.y * 16)-14
       screenCoords = [(44+(gridCoords.x * 16)),(44+(gridCoords.y * 16))]
       return screenCoords
 

   def draw(self):
      self.ship.updateGridCoords()
      position = self.ship.getPosition()
      self.old = self.rect

      #positionX = position[0].pop()
      #positionY = position[1].pop()
      
      self.rect = self.rect.move(position[0] - self.rect.x, position[1] - self.rect.y)

   # The x-position remains the same
   def update(self):

      self.ship.update()
      self.draw()

        
    